package com.tanhua.server.controller;

import com.tanhua.model.mongo.UserLike;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 用户管理控制层(接收请求 响应结果)
 */
@RestController
@RequestMapping("/users")
public class UserInfoController {


    @Autowired
    private UserInfoService userInfoService;

    /**
     * 用户资料 - 读取
     *
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity findUserInfo(Long userID){
        UserInfoVo userInfoVo = userInfoService.findUserInfo(userID);
        return ResponseEntity.ok(userInfoVo);
    }

    /**
     * 用户资料 - 保存(更新)
     *
     */
    @RequestMapping(method = RequestMethod.PUT)
    public ResponseEntity updateUserInfo(@RequestBody UserInfoVo userInfoVo){
        userInfoService.updateUserInfo(userInfoVo);
        return ResponseEntity.ok(null);
    }

    /**
     * 互相喜欢，粉丝，喜欢的人数量统计
     */
    @RequestMapping(method = RequestMethod.GET , value = "counts")
    public ResponseEntity getCounts(){
        Map<String, Long> map =userInfoService.getCounts();
        return ResponseEntity.ok(map);
    }


    /**
     * 互相喜欢，粉丝，喜欢的人，谁看过我列表
     */
    @GetMapping( "/friends/{type}")
    public ResponseEntity getPageByType(@PathVariable Integer type
            ,@RequestParam(value = "page",defaultValue = "1") Long page
            , @RequestParam(value = "pagesize",defaultValue = "10")Long pageSize
            ,@RequestParam(value = "nickname" ,required = false)String nickname){

        PageResult pageResult = userInfoService.getPageByType(type,page,pageSize,nickname);
        return ResponseEntity.ok(pageResult);
    }

}
